package thread;

public class testDemo18 {
    public static void main(String[] args) {
        Object lock=new Object();
        //创建线程1
        Thread t1=new Thread(()->{
            synchronized (lock){
                System.out.println("wait之前");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("wait之后");
            }
        });
        Thread t2=new Thread(()->{
            try {
                Thread.sleep(1000);//保证线程1能够成功加上锁
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (lock){
                System.out.println("notify之前");
                lock.notify();
                System.out.println("notify之后");
            }
        });
        t1.start();
        t2.start();

    }
}
